//
//  ScreenImageView.swift
//  MyColorPicker
//
//  Created by 火星人 on 2018/9/20.
//  Copyright © 2018年 火星人. All rights reserved.
//

import Cocoa

class ScreenImageView: NSImageView {
    
    var onMouseMovedHandle: ((_ event: NSEvent) -> Void)?
    var onMouseDownHandle: ((_ event: NSEvent) -> Void)?
    
    override func awakeFromNib() {
        let screen = NSScreen.main
        if let screen = screen {
            let rect = CGRect(origin: CGPoint.zero, size: screen.frame.size)
            let trArea = NSTrackingArea(rect: rect, options: [.mouseMoved,.activeAlways], owner: self, userInfo: nil)
            self.addTrackingArea(trArea)
        }
        else{
            print("screen is nil")
        }
    }

    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        // Drawing code here.
    }
    
    override func mouseMoved(with event: NSEvent) {
        self.onMouseMovedHandle?(event)
    }
    
    override func mouseDown(with event: NSEvent) {
        self.onMouseDownHandle?(event)
    }
    
    override func rightMouseDown(with event: NSEvent) {
        self.onMouseDownHandle?(event)
    }
    
}
